#ifndef INNER_TYPES_H_20180118
#define INNER_TYPES_H_20180118 1

#include <stdbool.h>
#include <stdint.h>
#include "uevent.h"
#include "ptr_vector.h"
#include "list.h"

#define FOREVER_TIME_MS 0xFFFFFFFF

struct FileDesc {
    int fd;
    UEventFileDescDetail detail;
    bool is_deleted;    //! 是否已被删除
};
typedef struct FileDesc FileDesc;
typedef PtrVector   FileDescVector;

struct TimerObject {
    int timer_id;

    uint32_t execute_time_ms;   //! 执行的时候点
    uint32_t interval_ms;  //! 对于单次，该值为0；多次时表示触发间隔

    UEventTimerDetail detail;

    struct list_head list_node;
};
typedef struct TimerObject TimerObject;

struct UEventLoop {
    bool in_loop;   //! 是否在主循环中
    bool keep_running;
    bool selecting;
    //pid_t current_thread_id;    //! 当前线程号

    int read_fd;
    int write_fd;

    //! file_desc相关
    bool executing_fd_callback;     //! 是否正在执行回调
    FileDescVector  *file_descs;   //! 文件描述符列表
    FileDescVector  *file_descs_tobe;  //! 将会被添加的文件描述符列表

    //! timer相关
    bool executing_timer_callback;  //! 是否正在执行定时器回调
    struct list_head timer_list;
};

#endif //INNER_TYPES_H_20180118
